package tech.mobi.child.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.mymmsc.android.app.util.AndroidXmlParser;
import org.mymmsc.android.app.util.XmlResult;
import org.mymmsc.api.http.HttpClient;

import tech.client.base.Global;
import tech.mobi.child.bean.GoodBuyBean;
import tech.mobi.child.bean.GoodBuywlBean;
import tech.mobi.child.bean.GroupBean;
import tech.mobi.child.utils.Configuration;

public class GoodService {

	/**
	 * 【新】订购产品-信息列表 ylj 2013-06－02
	 * 
	 * @param strFlag
	 *            标识：nomore more 0
	 * @param pageNumber
	 *            页码
	 * @param size
	 *            每页行数
	 * @param lastetUpdateTime
	 *            末次更新时间
	 * @return
	 */
	public static Object requestGoodList(String userName, String strFlag,
			String pageNumber, String size, String lastetUpdateTime,
			String strType, String strOrder, String strWhere,
			String strClientVersionNumber) {
		String domain = Configuration.URL + Configuration.PROJECTNAME
				+ "/servlet/Portal";
		AndroidXmlParser xp = null;
		String strXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
		strXML += "<mobile><request>";
		strXML += "<method>group-Goodlist</method>";
		strXML += "<accountid>" + userName + "</accountid>";
		strXML += "<ismore>" + strFlag.trim() + "</ismore>";
		strXML += "<lastedupdatetime>" + lastetUpdateTime.trim()
				+ "</lastedupdatetime>";
		strXML += "<typeid>" + strType + "</typeid>";
		strXML += "<orderid>" + strOrder + "</orderid>";
		strXML += "<whereid><![CDATA[" + strWhere + "]]></whereid>";
		strXML += "<pagenum>" + pageNumber.trim() + "</pagenum>";
		strXML += "<pagesize>" + size.trim() + "</pagesize>";
		strXML += "<clientos>3</clientos>";
		strXML += "<clientappversion>" + strClientVersionNumber.trim()
				+ "</clientappversion>";
		strXML += "</request></mobile>";

		HashMap<String, Object> map = new HashMap<String, Object>();
		List<GroupBean> list = new ArrayList<GroupBean>();
		String msg = "";
		String isLastPageStr = null;
		msg = HttpClient.PostXml(domain, strXML, Configuration.CLIENTINFO,
				"utf-8", Configuration.EXP_TIMEOUT);
		if (msg != null) {
			xp = new AndroidXmlParser(msg);
			try {
				isLastPageStr = xp.valueOf2("list", "updatetime");
				list = xp.valueOf5("item", GroupBean.class);
				map.put("updatetime", isLastPageStr);
				map.put("data", list);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return map;
	}

	/**
	 * 【新】订购产品-某条详细信息 ylj 2013-06－03
	 * 
	 * @param userName
	 * @param relId
	 * @param strClientVersionNumber
	 * @return
	 */
	public static Object requestGoodInfo(String userName, String relId,
			String strClientVersionNumber) {
		String domain = Configuration.URL + Configuration.PROJECTNAME
				+ "/servlet/Portal";
		AndroidXmlParser xp = null;
		String strXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n";
		strXML += "<mobile><request>";
		strXML += "<method>group-Goodinfo</method>";
		strXML += "<accountid>" + userName + "</accountid>";
		strXML += "<releaseid>" + relId.trim() + "</releaseid>";
		strXML += "<clientos>3</clientos>";
		strXML += "<clientappversion>" + strClientVersionNumber.trim()
				+ "</clientappversion>";
		strXML += "</request></mobile>";

		HashMap<String, Object> map = new HashMap<String, Object>();
		List<GroupBean> list = new ArrayList<GroupBean>();
		List<GoodBuyBean> list1 = new ArrayList<GoodBuyBean>();
		List<GoodBuyBean> list2 = new ArrayList<GoodBuyBean>();
		String msg = "";
		String isLastPageStr = null;
		msg = HttpClient.PostXml(domain, strXML, Configuration.CLIENTINFO,
				"utf-8", Configuration.EXP_TIMEOUT);
		if (msg != null) {
			xp = new AndroidXmlParser(msg);
			try {
				isLastPageStr = xp.valueOf2("list", "updatetime");
				list = xp.valueOf5("item", GroupBean.class);
				list1 = xp.valueOf5("item_mx", GoodBuyBean.class);
				list2 = xp.valueOf5("item_xz", GoodBuyBean.class);
				map.put("data", list);
				map.put("data1", list1);
				map.put("data2", list2);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return map;
	}

	
	
}
